package com.lhb.order.mapper;

import com.lhb.order.model.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert("insert into `order`( place_of_departure, place_of_arrival, date_of_departure, date_of_arrival, flight_number, passenger, order_type, order_date, price,flight_id, user_id) " +
            "values (#{placeOfDeparture},#{placeOfArrival},#{dateOfDeparture},#{dateOfArrival},#{flightNumber},#{passenger},#{orderType},#{orderDate},#{price},#{flightId},#{userId})")
    void addOrder(Order order);

    @Select("select * from `order` where user_id=#{userId}")
    List<Order> getAllOrder(Long userId);

    @Select("select * from `order` where user_id=#{userId} and order_type=#{orderType}")
    List<Order> getPaid(@Param("userId") Long userId, @Param("orderType") int orderType);

    @Select("select * from `order` where user_id=#{userId} and order_type=#{orderType}")
    List<Order> getUnpaid(@Param("userId") Long userId, @Param("orderType") int orderType);

    @Delete("delete from `order` where id=#{id}")
    void deleteOrder(Long id);

    @Update("update `order` set order_type=1 where id=#{id}")
    void modifyOrder(Long id);

    @Delete("delete from flight where id=#{id}")
    void deleteRepertory(Long id);
}
